//
//  WLLStatusRetweetView.swift
//  WLLWeibo
//
//  Created by 王乐乐 on 16/8/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
 import SnapKit
class WLLStatusRetweetView: UIView {
        /// 记录转发微博的底部视图约束
    var RetweetViewBottomConstraint : Constraint?
    
    
            ///  定义一个ViewModel 供外界赋值
    var statusViewModel :WLLStatusViewModel?{
        didSet{
            //微博正文
            contentLabel.text = statusViewModel?.statusModel?.retweeted_status?.text
//            "当我在夜里独赴幽会的时候,鸟儿不叫,风儿不吹,街道两旁的房屋沉默地站立着是我自己的脚镯越走越响使我羞怯当我站在凉台上倾听他的足音,树叶不摇,河水静止像熟睡的哨兵膝上的刀剑. 是我自己的心在狂跳＿＿我不知道怎样使它宁静. 当我爱来了,坐在我身旁,当我的身躯震颤,我的眼睫下垂,夜更深了,风吹灯灭,云片在繁星上曳过轻纱.是我自己胸前的珍宝放出光明.我不知道怎样把它遮起. "
            
            //卸载约束
            RetweetViewBottomConstraint?.uninstall()
            //判断是否有配图
            if statusViewModel?.statusModel?.retweeted_status?.pic_urls?.count  > 0 {   //有配图
             // 赋值
                pictureView.pictureInfo = statusViewModel?.statusModel?.retweeted_status?.pic_urls
                //设置约束
                self.snp_makeConstraints(closure: { (make) in
                    RetweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
                })
                //显示
                pictureView.hidden = false
                
            } else{
                //设置约束
                self.snp_makeConstraints(closure: { (make) in
                    RetweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                })
                //隐藏
                pictureView.hidden = true
            }
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
     //MARK: - 设置视图
    func setupUI ()  {
        backgroundColor = AdditionColor
         //添加控件
        //微博正文
        addSubview(contentLabel)
        //配图
        addSubview(pictureView)
        //添加约束
         //微博正文
        contentLabel.snp_makeConstraints { (make) in
            make.leading.top.equalTo(10)
        }
           //配图
        pictureView.snp_makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
            make.leading.equalTo((KSCREENW-250)/2)
        }
        self.snp_makeConstraints { (make) in
            RetweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
        }
        
    }
    
    
    
    
    
      //MARK: - 懒加载控件
    /// 微博正文
    private lazy var contentLabel:UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 15, maxWidth: KSCREENW-20)
    ///配图
    private lazy var pictureView : WLLStatusPictureView = WLLStatusPictureView()
    
    }
    









